# """
# Demonstrate using QPainter on a subclass of GLGraphicsItem.
# """
# ## Add path to library (just for examples; you do not need this)
# #import initExample
#
# # import pyqtgraph as pg
# # import pyqtgraph.opengl
# # from pyqtgraph.Qt import QtCore, QtGui
# # import OpenGL.GL as GL
# #
# # SIZE = 32
# #
# # class GLPainterItem(pg.opengl.GLGraphicsItem.GLGraphicsItem):
# #     def __init__(self, **kwds):
# #         super().__init__()
# #         glopts = kwds.pop('glOptions', 'additive')
# #         self.setGLOptions(glopts)
# #
# #     def compute_projection(self):
# #         modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
# #         projection = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
# #         mvp = projection.T @ modelview.T
# #         mvp = QtGui.QMatrix4x4(mvp.ravel().tolist())
# #
# #         # note that QRectF.bottom() != QRect.bottom()
# #         rect = QtCore.QRectF(self.view().rect())
# #         ndc_to_viewport = QtGui.QMatrix4x4()
# #         ndc_to_viewport.viewport(rect.left(), rect.bottom(), rect.width(), -rect.height())
# #
# #         return ndc_to_viewport * mvp
# #
# #     def paint(self):
# #         self.setupGLState()
# #
# #         painter = QtGui.QPainter(self.view())
# #         self.draw(painter)
# #         painter.end()
# #
# #     def draw(self, painter):
# #         painter.setPen(QtCore.Qt.GlobalColor.white)
# #         painter.setRenderHints(QtGui.QPainter.RenderHint.Antialiasing | QtGui.QPainter.RenderHint.TextAntialiasing)
# #
# #         rect = self.view().rect()
# #         af = QtCore.Qt.AlignmentFlag
# #
# #         painter.drawText(rect, af.AlignTop | af.AlignRight, 'TR')
# #         painter.drawText(rect, af.AlignBottom | af.AlignLeft, 'BL')
# #         painter.drawText(rect, af.AlignBottom | af.AlignRight, 'BR')
# #
# #         opts = self.view().cameraParams()
# #         lines = []
# #         center = opts['center']
# #         lines.append(f"center : ({center.x():.1f}, {center.y():.1f}, {center.z():.1f})")
# #         for key in ['distance', 'fov', 'elevation', 'azimuth']:
# #             lines.append(f"{key} : {opts[key]:.1f}")
# #         xyz = self.view().cameraPosition()
# #         lines.append(f"xyz : ({xyz.x():.1f}, {xyz.y():.1f}, {xyz.z():.1f})")
# #         info = "\n".join(lines)
# #         painter.drawText(rect, af.AlignTop | af.AlignLeft, info)
# #
# #         project = self.compute_projection()
# #
# #         hsize = SIZE // 2
# #         for xi in range(-hsize, hsize+1):
# #             for yi in range(-hsize, hsize+1):
# #                 if xi == -hsize and yi == -hsize:
# #                     # skip one corner for visual orientation
# #                     continue
# #                 vec3 = QtGui.QVector3D(xi, yi, 0)
# #                 pos = project.map(vec3).toPointF()
# #                 painter.drawEllipse(pos, 1, 1)
# #
# #
# # pg.mkQApp("GLPainterItem Example")
# # glv = pg.opengl.GLViewWidget()
# # glv.show()
# # glv.setWindowTitle('pyqtgraph example: GLPainterItem')
# # glv.setCameraPosition(distance=50, elevation=90, azimuth=0)
# #
# # griditem = pg.opengl.GLGridItem()
# # griditem.setSize(SIZE, SIZE)
# # griditem.setSpacing(1, 1)
# # glv.addItem(griditem)
# #
# # axisitem = pg.opengl.GLAxisItem()
# # axisitem.setSize(SIZE/2, SIZE/2, 1)
# # glv.addItem(axisitem)
# #
# # paintitem = GLPainterItem()
# # glv.addItem(paintitem)
# #
# # if __name__ == '__main__':
# #     pg.exec()
#
#
# from PyQt5 import QtGui
# from PyQt5.QtWidgets import QApplication
# ## build a QApplication before building other widgets
# import pyqtgraph as pg
#
# app = QApplication([])
#
# pg.mkQApp()
#
# ## make a widget for displaying 3D objects
# import pyqtgraph.opengl as gl
# view = gl.GLViewWidget()
# view.show()
#
# ## create three grids, add each to the view
# xgrid = gl.GLGridItem()
# ygrid = gl.GLGridItem()
# zgrid = gl.GLGridItem()
# view.addItem(xgrid)
# view.addItem(ygrid)
# view.addItem(zgrid)
#
# ## rotate x and y grids to face the correct direction
# xgrid.rotate(90, 0, 1, 0)
# ygrid.rotate(90, 1, 0, 0)
#
# ## scale each grid differently
# xgrid.scale(0.2, 0.1, 0.1)
# ygrid.scale(0.2, 0.1, 0.1)
# zgrid.scale(0.1, 0.2, 0.1)
#
# app.exec_()
#
#
# import sys
# import numpy as np
# from PyQt5 import QtWidgets
# import pyqtgraph as pg
#
# from qt_ui import Ui_MainWindow
#
# import pyqtgraph.opengl as gl
#
# class MyGraphWindow(QtWidgets.QMainWindow, Ui_MainWindow):
#
#     def __init__(self):
#
#         super(MyGraphWindow, self).__init__()
#         self.setupUi(self)  # 初始化窗口
#
#         self.p1, self.p2 = self.set_graph_ui()  # 设置绘图窗口
#
#         self.btn.clicked.connect(self.plot_sin_cos)  # 点击按键开始绘图
#
#     def set_graph_ui(self):
#
#         pg.setConfigOptions(antialias=True)  # pg全局变量设置函数，antialias=True开启曲线抗锯齿
#
#         win = pg.GraphicsLayoutWidget()  # 创建pg layout，可实现数据界面布局自动管理
#
#         # pg绘图窗口可以作为一个widget添加到GUI中的graph_layout，当然也可以添加到Qt其他所有的容器中
#         self.graph_layout.addWidget(win)
#
#         p1 = win.addPlot(title="sin 函数")  # 添加第一个绘图窗口
#         p1.setLabel('left', text='meg', color='#ffffff')  # y轴设置函数
#         p1.showGrid(x=True, y=True)  # 栅格设置函数
#         p1.setLogMode(x=False, y=False)  # False代表线性坐标轴，True代表对数坐标轴
#         p1.setLabel('bottom', text='time', units='s')  # x轴设置函数
#         # p1.addLegend()  # 可选择是否添加legend
#
#         win.nextRow()  # layout换行，采用垂直排列，不添加此行则默认水平排列
#         p2 = win.addPlot(title="cos 函数")
#         p2.setLabel('left', text='meg', color='#ffffff')
#         p2.showGrid(x=True, y=True)
#         p2.setLogMode(x=False, y=False)
#         p2.setLabel('bottom', text='time', units='s')
#         # p2.addLegend()
#
#         return p1, p2
#
#     def plot_sin_cos(self):
#         t = np.linspace(0, 20, 200)
#         y_sin = np.sin(t)
#         y_cos = np.cos(t)
#         self.p1.plot(t, y_sin, pen='g', name='sin(x)', clear=True)
#         self.p2.plot(t, y_cos, pen='g', name='con(x)', clear=True)
#
#     def plot_3dimage(self):
#         pass
#
#
#
# if __name__ == '__main__':
#     app = QtWidgets.QApplication(sys.argv)
#     myWin = MyGraphWindow()
#     myWin.show()
#     sys.exit(app.exec_())

# -*- coding: utf-8 -*-
"""
Demonstrate use of GLLinePlotItem to draw cross-sections of a surface.

"""
## Add path to library (just for examples; you do not need this)
#import initExample
#


# import pyqtgraph.opengl as gl
# import pyqtgraph as pg
# import numpy as np
#
#
#
#
# app = pg.mkQApp("GLLinePlotItem Example")
# w = gl.GLViewWidget()
# w.show()
# w.setWindowTitle('pyqtgraph example: GLLinePlotItem')
# w.setCameraPosition(distance=40)
#
# gx = gl.GLGridItem()
# gx.rotate(90, 0, 1, 0)
# gx.translate(-10, 0, 0)
# w.addItem(gx)
# gy = gl.GLGridItem()
# gy.rotate(90, 1, 0, 0)
# gy.translate(0, -10, 0)
#
# w.addItem(gy)
# gz = gl.GLGridItem()
# gz.translate(0, 0, -10)
# w.addItem(gz)
#
# n = 51
# y = np.linspace(-10,10,n)
# x = np.linspace(-10,10,100)
# for i in range(n):
#     yi = y[i]
#
#     d = np.hypot(x, yi)
#     z = 10 * np.cos(d) / (d+1)
#     pts = np.column_stack([x, np.full_like(x, yi), z])
#     plt = gl.GLLinePlotItem(pos=pts, color=pg.mkColor((i,n*1.3)), width=(i+1)/10., antialias=True)
#     w.addItem(plt)
#
# if __name__ == '__main__':
#     pg.exec()


# import sys
# from PyQt5 import QtCore, QtGui, QtWidgets
# from PyQt5.QtCore import Qt
# from PyQt5.QtGui import QColor, QOpenGLVersionProfile
# from PyQt5.QtWidgets import (QApplication, QWidget, QOpenGLWidget, QHBoxLayout)
#
#
# class MyGLWidget(QOpenGLWidget):
#
#     def __init__(self, parent=None):
#         super(MyGLWidget, self).__init__(parent)
#
#     def initializeGL(self):
#         version_profile = QOpenGLVersionProfile()
#         version_profile.setVersion(2, 0)
#         self.gl = self.context().versionFunctions(version_profile)
#         self.gl.initializeOpenGLFunctions()
#
#         # 设置背景色
#         self.gl.glClearColor(0.2, 0.4, 0.52, 1.0)
#         # 深度测试
#         self.gl.glEnable(self.gl.GL_DEPTH_TEST)
#
#     def paintGL(self):
#         self.gl.glClear(self.gl.GL_COLOR_BUFFER_BIT | self.gl.GL_DEPTH_BUFFER_BIT)
#         self.gl.glLoadIdentity()
#
#         # self.gl.glRotated(30.0, 1.0, 0.0, 0.0)
#         self.gl.glBegin(self.gl.GL_TRIANGLES)
#         self.gl.glColor3d(1.0, 0.0, 0.0)
#         self.gl.glVertex3d(0.0, 1.0, 0.0)
#         self.gl.glColor3d(0.0, 1.0, 0.0)
#         self.gl.glVertex3d(-1.0, -1.0, 0.0)
#         self.gl.glColor3d(0.0, 0.0, 1.0)
#         self.gl.glVertex3d(1.0, -1.0, 0.0)
#         self.gl.glEnd()
#
#     def resizeGL(self, width, height):
#         side = min(width, height)
#         if side < 0:
#             return
#
#         # 视口
#         self.gl.glViewport((width - side) // 2, (height - side) // 2, side, side)
#         self.gl.glMatrixMode(self.gl.GL_PROJECTION)
#         self.gl.glLoadIdentity()
#         # 正交投射
#         self.gl.glOrtho(-1.5, 1.5, -1.5, 1.5, -10, 10)
#         self.gl.glMatrixMode(self.gl.GL_MODELVIEW)
#
#
# class DemoOpenGLWidget(QWidget):
#     def __init__(self, parent=None):
#         super(DemoOpenGLWidget, self).__init__(parent)
#
#         # 设置窗口标题
#         self.setWindowTitle('实战PyQt5: QOpenGLWidget Demo!')
#         # 设置窗口大小
#         self.resize(400, 320)
#
#         self.initUi()
#
#     def initUi(self):
#         glWidget = MyGLWidget()
#
#         mainLayout = QHBoxLayout()
#         mainLayout.addWidget(glWidget)
#
#         self.setLayout(mainLayout)
#
#
# if __name__ == '__main__':
#     app = QApplication(sys.argv)
#     window = DemoOpenGLWidget()
#     window.show()
#     sys.exit(app.exec())
#

# -*- coding: utf-8 -*-
"""
Demonstrate use of GLLinePlotItem to draw cross-sections of a surface.

"""
## Add path to library (just for examples; you do not need this)
#import initExample

import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np

class plot_3d():
    app = pg.mkQApp("GLLinePlotItem Example")
    w = gl.GLViewWidget()
    w.show()
    w.setWindowTitle('pyqtgraph example: GLLinePlotItem')
    w.setCameraPosition(distance=40)

    gx = gl.GLGridItem()
    #gx.rotate(90, 0, 1, 0)
    center = [1, 2, 3]
    radius = 10

    # data
    u = np.linspace(0, 2 * np.pi, 100)
    v = np.linspace(0, np.pi, 100)
    x = radius * np.outer(np.cos(u), np.sin(v)) + center[0]
    y = radius * np.outer(np.sin(u), np.sin(v)) + center[1]
    z = radius * np.outer(np.ones(np.size(u)), np.cos(v)) + center[2]

    gx.translate(0, 0, 0)
    w.addItem(gx)
    # gy = gl.GLGridItem()
    # gy.rotate(90, 1, 0, 0)
    # gy.translate(0, -10, 0)
    # w.addItem(gy)
    # gz = gl.GLGridItem()
    # gz.translate(0, 0, -10)
    # w.addItem(gz)

if __name__ == '__main__':
    pg.exec()

